package com.egg.eggdemo;

import redis.clients.jedis.Jedis;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class RedisInit {
    private static final String COUPON_KEY = "egg_break:coupons";
    private static final String PROB_KEY = "egg_break:probabilities";
    private static final String DAY_KEY = "egg_break:current_day";
    private static final String DAILY_INIT_KEY = "egg_break:daily_init"; // 新增：记录每日初始数量


    public static void main(String[] args) {
        // 1. 连接Redis
        try (Jedis jedis = new Jedis("localhost", 6379)) {
            log.info("连接Redis成功: {}", jedis.ping());

            // 新增：1. 初始化每日奖券数量
            jedis.hset(DAILY_INIT_KEY, "5", "1000");
            jedis.hset(DAILY_INIT_KEY, "7", "500");
            jedis.hset(DAILY_INIT_KEY, "10", "200");


            // 2. 初始化当前奖券数量
            jedis.hset(COUPON_KEY, "5", "1000");
            jedis.hset(COUPON_KEY, "7", "500");
            jedis.hset(COUPON_KEY, "10", "200");

            // 3. 初始化中奖概率（概率和需要小于1，留出未中奖概率）
            jedis.hset(PROB_KEY, "5", "0.3");
            jedis.hset(PROB_KEY, "7", "0.2");
            jedis.hset(PROB_KEY, "10", "0.1");
            // 未中奖概率为：1 - (0.3 + 0.2 + 0.1) = 0.4


            // 4. 设置活动第一天
            jedis.set(DAY_KEY, "1");

            log.info("初始化数据完成！");
        } catch (Exception e) {
            log.error("初始化失败", e);
        }
    }
}
